﻿angular.module('angularApp.controllers', [])

.controller('AppCtrl', function ($scope, $ionicModal, $timeout) {
    //$(document).bind('keydown', function (e) {
    //    console.debug('Key pressed');
    //    console.debug(e);
    //});

    $scope.output = "keys: ";

    $scope.sendKey = function (key) {
        //var serviceUrl = "http://localhost:180";
        var serviceUrl = "http://192.168.0.10:181";

        $.jsonp({
            url: serviceUrl + "/wcf/PressKey?callback=?"
            , data: {
                key: key
            }
            , success: function (data) {
                console.debug(data);
                var response;
                for (var prop in data)
                    response = data[prop];

                if (response.Success == true) {
                    $scope.output += key + ', ';

                    $scope.$apply()
                }
            }
            , error: function (jqReq, errorMsg) {
                console.error("Service error");
            }
        });
    };
});